//logs.js
const chooseLocation = requirePlugin('chooseLocation');
var time = require("../../utils/util.js");
// 引用百度地图微信小程序JSAPI模块 
var bmap = require('../../libs/bmap-wx.min.js');
var wxMarkerData = []; //定位成功回调对象
const app = getApp()
import Dialog from '../../@vant/weapp/dialog/dialog';
import Toast from '../../@vant/weapp/toast/toast';
Page({
  data: {
    orderid: '',
    ak: "KdZjo4KT7pfqWZovH40CIgtxOlFkax03", //填写申请到的ak
    fileList: [],
    value: '',
    time: '',
    type: '', //违法类型
    typeid: '',
    typelist: '',
    showilltype: false,
    tempFilePaths: '',
    images: [],
    videos: [],
    images1: [], //不加http
    videos1: [], //不加http
    videos2: [], //缩略图
    show: false,
    show1: false,
    road: '', //所选辖区
    road1: '', //辖区改变
    areaList: [ //自选路段数据
      {
        values: [],
        className: 'column1',
      },
      {
        values: [],
        className: 'column2',
      },
      {
        values: [],
        className: 'column3',
      }
    ],
    lng: '',
    lat: '',
    nowcity: '',
    city: [], //城市
    highspeed: [], //高速
    Jurisdiction: [], //辖区
    carroad: false,
    Manualtext: true,
    selroad: false,
    cartype: '',
    cartypeid: '',
    cartime: false,
    minHour: 10,
    maxHour: 20,
    minDate: new Date().getTime(),
    maxDate: new Date().getTime(),
    currentDate: new Date().getTime(),
    showcar: '',
    columns: [],
    username: '',
    idnumber: '',
    phone: '',
    btnshow: false,
    shownumber: '',
    isKeyboard: !1,
    isNumberKB: !1,
    tapNum: !1,
    disableKey: "1234567890港澳学",
    keyboardNumber: "1234567890ABCDEFGHJKLMNPQRSTUVWXYZ港澳学",
    keyboard1: "京沪粤津冀晋蒙辽吉黑苏浙皖闽赣鲁豫鄂湘桂琼渝川贵云藏陕甘青宁新",
    inputPlates: {
      index0: "",
      index1: "",
      index2: "",
      index3: "",
      index4: "",
      index5: "",
      index6: "",
      index7: ""
    },
    inputOnFocusIndex: "",
    flag: true,
    reasonshow: true,
    overlayshow: false,
    inputhide: false,
    bglist: [], // 占位字符串不要删
    radio: '1',
    examples: false,
    show2: true,
    overlay: false,
    num: 2,
    showroad: false,
    roadtext: '',
    roadtextid: '',
    roadlist: [{
      values: [],
      className: 'column1',
    },
    {
      values: [],
      className: 'column2',
    }],
    jurisdiction: "",
    jurisdictionId: "",
  },
  onroad: function(){
    this.setData({
      showroad: false,
    })
  },
  Confirmroad: function(e){
    console.log(e);
    this.setData({
      showroad: false,
      roadtext: e.detail.value[1].text,
      roadtextid: e.detail.value[1].id,
    })
  },
  focusimput: function(){
    this.setData({
      showroad: true,
    })
  },
  onLoad: function (options) {
    // console.log(options);
    var that = this
    /* 获取定位地理位置 */
    // 新建bmap对象 
    var BMap = new bmap.BMapWX({
      ak: that.data.ak
    });
    var fail = function (data) {
      // console.log(data);
    };
    var success = function (data) {
      //返回数据内，已经包含经纬度
      console.log(data,'经纬度城市');
      //使用wxMarkerData获取数据
      const wxMarkerData = data.wxMarkerData;
      const originalData = data.originalData;
      //把所有数据放在初始化data内
      that.setData({
        lat: wxMarkerData[0].latitude,
        lng: wxMarkerData[0].longitude,
        nowcity: originalData.result.addressComponent.city
      });
      that.getLocation(wxMarkerData[0].longitude, wxMarkerData[0].latitude, data.originalData.result.addressComponent.city)
    }
    // 发起regeocoding检索请求 
    BMap.regeocoding({
      fail: fail,
      success: success
    });
  },
  onReady: function () {
    var that = this;
    wx.request({
      url: time.httpurl + '/api/getCarTypeAll',
      method: 'GET',
      header: {
        'AppType': 'AppType',
        'Authorization': wx.getStorageSync("token"),
      },
      success: function (res) {
        console.log(res, 'cartype');
        if (res.data.code == 200) {
          that.setData({
            columns: res.data.data
          })
        } else if (res.data.code == 401 || res.data.code == 403) {
          app.login();
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
    wx.request({     
      url: time.httpurl + '/api/getTypeTemplateAll',
      method: 'GET',
      header: {
        'AppType': 'AppType',
        'Authorization': wx.getStorageSync("token"),
      },
      success: function (res) {
        console.log(res,'type');
        if(res.data.code == 200){
          that.setData({
            typelist: res.data.data
          })
        }else if(res.data.code == 401 || res.data.code == 403){
          app.login();
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }     
      }
    })
  },
  //提交
  save: function () {
    var that = this; 
    if(that.data.radio == 1 && that.data.images1.length < that.data.num){
      wx.showToast({
        title: '图片至少上传 '+ that.data.num +' 张，请继续上传,谢谢！',
        icon: 'none',
        duration: 3000
      })
    }else if(that.data.radio == 2  && that.data.videos1.length == 0 ){
      wx.showToast({
        title: '您还没有上传视频，请继续上传,谢谢！',
        icon: 'none',
        duration: 3000
      })
    }else if (that.data.type == '') {
      wx.showToast({
        title: '请将必填信息填写完整,谢谢！',
        icon: 'none',
        duration: 3000
      })
    }else {
      that.saverequest();
    }
    
  },
  saverequest: function () {
    var that = this;
    var xq = '';
    var xqid = '';
    var piclist = '';
    var videolist = '';
    var videoimg = '';
    var locationInformation = '';
    
    xq =  that.data.road.split('-')[2];
    xqid = that.data.jurisdictionId;
    locationInformation = that.data.road;
    if(that.data.radio == 1){
      piclist = that.data.images1.join(',');
      videolist = '';
      videoimg = '';
    }else{
      piclist = '';
      videolist = that.data.videos1.join(',');
      videoimg = that.data.videos2.join(',');
    }
    console.log(xq,xqid,piclist,videolist,videoimg,locationInformation)
    if (xq == '' || xqid == '') {
      wx.showToast({
        title: '您所处位置不在河南高速辖区范围内,不能使用现场举报,谢谢！',
        icon: 'none',
        duration: 3000
      })
    }else{
      wx.requestSubscribeMessage({
        tmplIds: ['gsFHHund1fjqVHov1H2kdkxCu5UnoTO6Zl-333lUm3c'],
        success(res) {
          console.log(res)
          wx.request({ //提交
            url: time.httpurl + '/api/addOrder',
            method: 'POST',
            data: {
              "carNumber": that.data.carnumber,
              "carType": that.data.cartypeid,
              "content": that.data.value,
              "illegalTime": that.data.time,
              "illegalType": that.data.typeid,
              "jurisdiction": xq,
              "jurisdictionId": xqid,
              "locationInformation": locationInformation,
              "pictureList": piclist,
              "status": 0,
              "video": videolist,
              "videoImageList": videoimg,
              "deptId": xq
            },
            header: {
              'AppType': 'AppType',
              'Authorization': wx.getStorageSync("token"),
            },
            success: function (res) {
              // console.log(res,'提交');
              if (res.data.code == 200) {
                wx.navigateBack({
                  url: '../index/index'
                })
              } else if (res.data.code == 401 || res.data.code == 403) {
                app.login();
              } else {
                wx.showToast({
                  title: res.data.msg,
                  icon: 'none',
                  duration: 2000
                })
              }
            }
          })
        }
      })
    }
    
  },
  //通过经纬度查辖区
  getLocation: function (lon, lat, city) {
    var that = this;
    wx.request({
      url: time.httpurl + '/api/getLocation',
      method: 'POST',
      data: {
        city: city,
        lon: lon,
        lat: lat,
      },
      header: {
        'AppType': 'AppType',
        'Authorization': wx.getStorageSync("token"),
      },
      success: function (res) {
        console.log(res,'经纬度查辖区');
        if (res.data.code == 200) {
          that.setData({
            road: res.data.data.city + '-' + res.data.data.street + '+' + res.data.data.kilometers + '-' + res.data.data.area,
            jurisdictionId: res.data.data.jurisdictionId
          })
          wx.request({
            url: time.httpurl + '/api/getImageCount/' + res.data.data.jurisdictionId,
            method: 'GET',
            header: {
              'AppType': 'AppType',
              'Authorization': wx.getStorageSync("token"),
            },
            success: function (res) {
              console.log(res,'num');
              if (res.data.code == 200) {
                that.setData({
                  num: res.data.data.uploadImageMin
                })    
              }
            },
          })
        } else if (res.data.code == 401 || res.data.code == 403) {
          app.login();
        } else {
          that.setData({
            road: '位置信息不在河南高速辖区范围内，无法举报，谢谢！'
          })
        }
      },
      fail: function (e) {
        Dialog.alert({
          title: '错误信息',
          message: JSON.stringify(e),
        }).then(() => {
          // on close
        });
      }
    })
  },
  //本地上传图片
  localupload: function () {
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['album'],
      success: function (res) {
        // console.log(res);
        that.setData({
          show: false
        });
        wx.uploadFile({
          url: time.httpurl + '/api/fileUpload',
          filePath: res.tempFilePaths[0],
          name: 'file',
          header: {
            'AppType': 'AppType',
            'Authorization': wx.getStorageSync("token"),
          },
          success(data) {
            // console.log(data)
            if (JSON.parse(data.data).code == 200) {
              const arraydata = [JSON.parse(data.data).data.webPath]
              that.setData({
                images: that.data.images.concat([time.httpurlvideo + JSON.parse(data.data).data.webPath])
              });
              that.setData({
                images1: that.data.images1.concat(arraydata)
              });
            } else if (JSON.parse(data.data).code == 401 || JSON.parse(data.data).code == 403) {
              app.login();
            } else {
              wx.showToast({
                title: JSON.parse(data.data).msg,
                icon: 'none',
                duration: 3000
              })
            }
          }
        })
      }
    })
  },
  //拍照
  camera: function () {
    var that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['camera'],
      success: function (res) {
        // console.log(res)
        that.setData({
          show: false
        });
        wx.uploadFile({
          url: time.httpurl + '/api/fileUpload',
          filePath: res.tempFilePaths[0],
          name: 'file',
          header: {
            'AppType': 'AppType',
            'Authorization': wx.getStorageSync("token"),
          },
          success(data) {
            // console.log(data)
            if (JSON.parse(data.data).code == 200) {
              const arraydata = [JSON.parse(data.data).data.webPath]
              that.setData({
                images: that.data.images.concat([time.httpurlvideo + JSON.parse(data.data).data.webPath])
              });
              that.setData({
                images1: that.data.images1.concat(arraydata)
              });
            } else if (JSON.parse(data.data).code == 401 || JSON.parse(data.data).code == 403) {
              app.login();
            } else {
              wx.showToast({
                title: JSON.parse(data.data).msg,
                icon: 'none',
                duration: 3000
              })
            }
          }
        })
      }
    })
  },
  //本地上传视频
  uploadvideo: function () {
    var that = this;
    wx.chooseVideo({
      maxDuration: 15,
      sourceType: ['album'],
      success: function (res) {
        // console.log(res); 
        that.setData({
          show: false
        });
        if (res.duration > 15) {
          Dialog.confirm({
            message: '上传视频时长不能超过15秒，请剪辑后上传',
          }).then(() => {
            // wx.openVideoEditor({
            //   filePath: res.tempFilePath,
            //   success (data){
            //     console.log(data)
            //     that.setData({
            //       overlayshow: true
            //     })  
            //     wx.showLoading({
            //       title: '上传中',
            //     })
            //     that.setData({
            //       inputhide: true
            //     })
            //     that.upvideo(data.tempFilePath);
            //   }
            // })
          }).catch(() => {
            // on cancel
          });
        } else {
          // that.setData({
          //   overlayshow: true
          // })  
          // wx.showLoading({
          //   title: '上传中',
          // })
          // that.setData({
          //   inputhide: true
          // })
          Toast.loading({
            message: '上传中...',
            forbidClick: true,
          });
          that.upvideo(res.tempFilePath);
        }

      }
    })
  },
  upvideo: function (filePath) {
    var that = this;
    wx.uploadFile({
      url: time.httpurl + '/api/fileUpload',
      filePath: filePath,
      name: 'file',
      timeout: 180000,
      header: {
        'AppType': 'AppType',
        'Authorization': wx.getStorageSync("token"),
      },
      success(data) {
        // console.log(data) 
        // wx.hideLoading()
        // that.setData({
        //   overlayshow: false
        // })
        // that.setData({
        //   inputhide: false
        // })
        Toast.clear();
        if (JSON.parse(data.data).code == 200) {
          const arr = [time.httpurlvideo + JSON.parse(data.data).data.webPath]
          that.setData({
            videos: that.data.videos.concat(arr)
          });
          that.setData({
            videos1: that.data.videos1.concat([JSON.parse(data.data).data.webPath])
          });
          that.setData({
            videos2: that.data.videos2.concat([JSON.parse(data.data).data.videoImageWebPath])
          });
        } else if (JSON.parse(data.data).code == 401 || JSON.parse(data.data).code == 403) {
          app.login();
        } else {
          wx.showToast({
            title: JSON.parse(data.data).msg,
            icon: 'none',
            duration: 3000
          })
        }
      }
    })
  },
  //拍摄
  shot: function () {
    var that = this
    wx.chooseVideo({
      maxDuration: 15,
      sourceType: ['camera'],
      success: function (res) {
        // console.log(res)  
        that.setData({
          show: false
        });
        Toast.loading({
          message: '上传中...',
          forbidClick: true,
        });
        wx.uploadFile({
          url: time.httpurl + '/api/fileUpload',
          filePath: res.tempFilePath,
          name: 'file',
          timeout: 180000,
          header: {
            'AppType': 'AppType',
            'Authorization': wx.getStorageSync("token"),
          },
          success(data) {
            // console.log(time.httpurlvideo,JSON.parse(data.data)) 

            Toast.clear();
            if (JSON.parse(data.data).code == 200) {
              const arr = [time.httpurlvideo + JSON.parse(data.data).data.webPath]
              that.setData({
                //上传完并显示照片
                videos: that.data.videos.concat(arr)
              });
              that.setData({
                videos1: that.data.videos1.concat([JSON.parse(data.data).data.webPath])
              });
              that.setData({
                videos2: that.data.videos2.concat([JSON.parse(data.data).data.videoImageWebPath])
              });
              // if (that.data.images.length == that.data.num) {
              //   that.setData({
              //     show1: true
              //   });
              // }
            } else if (JSON.parse(data.data).code == 401 || JSON.parse(data.data).code == 403) {
              app.login();
            } else {
              wx.showToast({
                title: JSON.parse(data.data).msg,
                icon: 'none',
                duration: 3000
              })
            }
          }
        })
      }
    })
  },
  
  // 删除照片
  delete: function (e) {
    // console.log(e);
    var that = this;
    const index = e.currentTarget.dataset.index;
    const url = e.currentTarget.dataset.url;
    if (url.charAt(url.length - 1) == 'g') {
      const images = that.data.images;
      images.splice(index, 1);
      that.setData({
        images: images
      });
      const images1 = that.data.images1;
      images1.splice(index, 1);
      that.setData({
        images1: images1
      });
    } else {
      const videos = that.data.videos;
      videos.splice(index, 1);
      that.setData({
        videos: videos
      });
      const videos1 = that.data.videos1;
      videos1.splice(index, 1);
      that.setData({
        videos1: videos1
      });
      const videos2 = that.data.videos2;
      videos2.splice(index, 1);
      that.setData({
        videos2: videos2
      });
    }
    // console.log(that.data.images,that.data.images1,that.data.videos,that.data.videos1)
  },
  onChange(event) {
    this.setData({
      radio: event.detail,
    });
  },

  onClick(event) {
    const { name } = event.currentTarget.dataset;
    this.setData({
      radio: name,
    });
  },
  showtype: function(){
    this.setData({
      showilltype: true
    })
  },
  onCloseilltype: function(){
    this.setData({
      showilltype: false
    })
  },
  onConfirmilltype: function(event){
    var that = this;
    console.log(event)
    this.setData({
      showilltype: false,
      type: event.detail.value.text,
      typeid: event.detail.value.illegalType,
    })
    console.log(that.data.typeid)
    var arr = [];
    if(event.detail.value.imageListObj != null){
      for(var i=0;i<event.detail.value.imageListObj.length;i++){
        arr.push(time.httpurlcard + event.detail.value.imageListObj[i])
      }
    }
    this.setData({
      bglist: arr,
    })
  },
  searchExam: function(){
    var that = this;
    if(that.data.typeid === ''){
      wx.showToast({
        title: '请先选择违法类型，才能查看示例图',
        icon: 'none',
        duration: 3000
      })
    }else if(that.data.bglist.length == 0){
      wx.showToast({
        title: '现无示例图',
        icon: 'none',
        duration: 3000
      })
    }else{
      that.setData({
        examples: true
      })
    }   
  },
  //地图选点
  location() {
    this.setData({ 
      Manualtext: true
    })
    const key = 'B3GBZ-ZNIL3-TUG3U-34UYU-DO7D3-EEFNI'; //使用在腾讯位置服务申请的key
    const referer = '河南高速公安违法举报'; //调用插件的app的名称
    const category = '生活服务,娱乐休闲';

    wx.navigateTo({
      url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer
    });
  },
  //地图选点返回结果
  onShow() {
    const location = chooseLocation.getLocation(); // 如果点击确认选点按钮，则返回选点结果对象，否则返回null
    // console.log(location)
    if (location != null) {
      this.getLocation(this.gcj02tobd09(location.longitude, location.latitude)[0], this.gcj02tobd09(location.longitude, location.latitude)[1], location.city)
    }
    var DATE = time.formatTime(new Date());
    console.log(DATE)
    this.setData({
      time: DATE
    });
  },
  showcartype() {
    this.setData({
      showcar: true
    });
  },
  onClosecar() {
    this.setData({
      showcar: false
    });
  },
  error: function (e) {
    // console.log(e,333)
  },
  showcartime() {
    this.setData({
      cartime: true
    });
  },
  onClosetime() {
    this.setData({
      cartime: false
    });
  },
  onInput(event) {
    this.setData({
      currentDate: event.detail,
    });
  },
  //时间 确定
  onConfirmtime(event) {
    // console.log(event)
    // const { picker, value, index } = event.detail;
    this.setData({
      time: time.formatTime(event.detail)
    });
    this.setData({
      cartime: false
    });
  },
  timeFormat(time) { // 时间格式化
    let year = time.getFullYear();
    let month = time.getMonth() + 1;
    let day = time.getDate();
    let hour = time.getHours();
    let mm = time.getMinutes();
    return year + '-' + month + '-' + day + '- ' + hour + ':' + mm
  },
  //举报车辆类型
  onConfirm(event) {
    console.log(event)
    const {
      picker,
      value,
      index
    } = event.detail;
    this.setData({
      cartype: event.detail.value.text
    });
    this.setData({
      cartypeid: event.detail.value.id
    });
    this.setData({
      showcar: false
    });
  },
  showPopup() {
    this.setData({
      show: true
    });
  },

  onClose() {
    this.setData({
      show: false
    });
  },
  bindManual: function(){
    this.setData({
      Manualtext: false,
      selroad: true
    })
  },
  bindButtonTap: function () {
    this.setData({
      Manualtext: true,
      carroad: true
    })
  },
  onConfirmcar: function (data) {
    // console.log(data)
    var that = this;
    this.setData({
      carroad: false
    })
    this.setData({
      road: data.detail.value[0].text + '-' + data.detail.value[1].text + '-' + data.detail.value[2].text,
      jurisdictionId: data.detail.value[2].id
    })
    wx.request({
      url: time.httpurl + '/api/getImageCount/' + data.detail.value[2].id,
      method: 'GET',
      header: {
        'AppType': 'AppType',
        'Authorization': wx.getStorageSync("token"),
      },
      success: function (res) {
        console.log(res,'num');
        if (res.data.code == 200) {
          that.setData({
            num: res.data.data.uploadImageMin
          })    
        }
      },
    })
  },
  onCloseroad: function () {
    this.setData({
      carroad: false
    })
  },
  //辖区发生改变
  changeroad: function (data) {
    var that = this;
    console.log(data.detail,that.data.road1)
    if (data.detail.value[0].text != that.data.road1[0].text) {
      that.highspeed(data.detail.value[0].id)
    } else {
      if (data.detail.value[1].text != that.data.road1[1].text) {
        that.Jurisdictio(data.detail.value[0].id, data.detail.value[1].id)
      }
    }
    that.setData({
      road1: data.detail.value
    })

  },
  changeroad1: function (data) {
    var that = this;
    console.log(data.detail,that.data.road2)
    if (data.detail.value[0].text != that.data.road2[0].text) {
      that.highspeed1(data.detail.value[0].id)
    }
    that.setData({
      road2: data.detail.value
    })

  },
  highspeed1: function (city) {
    var that = this;
    wx.request({ //高速
      url: time.httpurl + '/api/getStreet',
      method: 'POST',
      data: {
        city: city
      },
      header: {
        'AppType': 'AppType',
        'Authorization': wx.getStorageSync("token"),
      },
      success: function (res) {
        console.log(res.data.data,'高速');
        if(res.data.data.length != 0){
          that.setData({
            'roadlist[1].values': res.data.data
          });
        }else{
          that.setData({
            'roadlist[1].values': []
          });
        }   
      }
    })
  },
  //请求高速 辖区
  highspeed: function (city) {
    var that = this;
    wx.request({ //高速
      url: time.httpurl + '/api/getStreet',
      method: 'POST',
      data: {
        city: city
      },
      header: {
        'AppType': 'AppType',
        'Authorization': wx.getStorageSync("token"),
      },
      success: function (res) {
        console.log(res.data.data,'高速');
        if(res.data.data.length !=0){
          that.setData({
            highspeed: res.data.data
          });
          that.setData({
            'areaList[1].values': res.data.data
          });
          wx.request({ //辖区
            url: time.httpurl + '/api/getArea',
            method: 'POST',
            data: {
              city: city,
              street: res.data.data[0].id,
            },
            header: {
              'AppType': 'AppType',
              'Authorization': wx.getStorageSync("token"),
            },
            success: function (res) {
              // console.log(res.data.data,'辖区');
              if(res.data.data.length !=0){
                that.setData({
                  Jurisdiction: res.data.data
                });
                that.setData({
                  'areaList[2].values': res.data.data
                });
                console.log(that.data.areaList)
              }else{
                that.setData({
                  Jurisdiction: []
                });
                that.setData({
                  'areaList[2].values': []
                });
              }           
            }
          })
        }else{
          that.setData({
            highspeed: [],
            Jurisdiction: []
          });
          that.setData({
            'areaList[1].values': [],
            'areaList[2].values': []
          });
        }   
      }
    })
  },
  //请求辖区
  Jurisdictio: function (city, street) {
    var that = this;
    wx.request({ //辖区
      url: time.httpurl + '/api/getArea',
      method: 'POST',
      data: {
        city: city,
        street: street,
      },
      header: {
        'AppType': 'AppType',
        'Authorization': wx.getStorageSync("token"),
      },
      success: function (res) {
        // console.log(res.data.data,'辖区');
        that.setData({
          Jurisdiction: res.data.data
        });
        that.setData({
          'areaList[2].values': res.data.data
        });
      }
    })
  },
  /**
   * 坐标系转化
   */
  gcj02tobd09: function (lng, lat) {
    var that = this
    var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
    var PI = 3.1415926535897932384626;
    var a = 6378245.0;
    var ee = 0.00669342162296594323;
    var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
    var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
    var bd_lng = z * Math.cos(theta) + 0.0065;
    var bd_lat = z * Math.sin(theta) + 0.006;
    return [bd_lng, bd_lat]
  },
  //车牌号
  showcarnumber() {
    // console.log(this.data.cartype)
    if (this.data.cartype == '小型新能源车牌号' || this.data.cartype == '大型新能源车牌号') {
      this.setData({
        flag: false,
        inputPlates: {
          index0: this.data.inputPlates.index0,
          index1: this.data.inputPlates.index1,
          index2: this.data.inputPlates.index2,
          index3: this.data.inputPlates.index3,
          index4: this.data.inputPlates.index4,
          index5: this.data.inputPlates.index5,
          index6: this.data.inputPlates.index6,
          index7: this.data.inputPlates.index7
        },
      })
    } else {
      this.setData({
        flag: true,
        inputPlates: {
          index0: this.data.inputPlates.index0,
          index1: this.data.inputPlates.index1,
          index2: this.data.inputPlates.index2,
          index3: this.data.inputPlates.index3,
          index4: this.data.inputPlates.index4,
          index5: this.data.inputPlates.index5,
          index6: this.data.inputPlates.index6,
        },
      })
    }
    this.setData({
      shownumber: true
    });
  },
  onClosecarnumber() {
    this.setData({
      shownumber: false
    });
  },


  //切换车牌
  changeplate: function () {
    var that = this;
    that.setData({
      flag: false,
      inputPlates: {
        index0: "",
        index1: "",
        index2: "",
        index3: "",
        index4: "",
        index5: "",
        index6: "",
        index7: ""
      },
    })
  },
  //切换车牌
  // changeplate1: function () {
  //   var that = this;
  //   that.setData({
  //     flag: true,
  //     inputPlates: {
  //       index0: "",
  //       index1: "",
  //       index2: "",
  //       index3: "",
  //       index4: "",
  //       index5: "",
  //       index6: "",
  //       index7: ""
  //     },
  //   })
  // },

  inputClick: function (t) {
    var that = this;
    // console.log('输入框:', t)
    that.setData({
      inputOnFocusIndex: t.target.dataset.id,
      isKeyboard: !0
    })
    "0" == this.data.inputOnFocusIndex ? that.setData({
      tapNum: !1,
      isNumberKB: !1
    }) : "1" == this.data.inputOnFocusIndex ? that.setData({
      tapNum: !1,
      isNumberKB: !0
    }) : that.setData({
      tapNum: !0,
      isNumberKB: !0
    });

  },

  //键盘点击事件
  tapKeyboard: function (t) {
    t.target.dataset.index;
    var a = t.target.dataset.val;
    // console.log('键盘:',a)
    switch (this.data.inputOnFocusIndex) {
      case "0":
        this.setData({
          "inputPlates.index0": a,
          inputOnFocusIndex: "1"
        });
        break;

      case "1":
        this.setData({
          "inputPlates.index1": a,
          inputOnFocusIndex: "2"
        });
        break;

      case "2":
        this.setData({
          "inputPlates.index2": a,
          inputOnFocusIndex: "3"
        });
        break;

      case "3":
        this.setData({
          "inputPlates.index3": a,
          inputOnFocusIndex: "4"
        });
        break;

      case "4":
        this.setData({
          "inputPlates.index4": a,
          inputOnFocusIndex: "5"
        });
        break;

      case "5":
        this.setData({
          "inputPlates.index5": a,
          inputOnFocusIndex: "6"
        });
        break;

      case "6":
        this.setData({
          "inputPlates.index6": a,
          inputOnFocusIndex: "7"
        });
        break;

      case "7":
        this.setData({
          "inputPlates.index7": a,
          inputOnFocusIndex: "7"
        });

    }
    var n = this.data.inputPlates.index0 + this.data.inputPlates.index1 + this.data.inputPlates.index2 + this.data.inputPlates.index3 + this.data.inputPlates.index4 + this.data.inputPlates.index5 + this.data.inputPlates.index6 + this.data.inputPlates.index7
    // console.log('车牌号:',n)
    this.checkedSubmitButtonEnabled();
  },
  //键盘关闭按钮点击事件
  tapSpecBtn: function (t) {
    if (1 == t.target.dataset.index) {
      this.setData({
        shownumber: false
      });
    }
    if (this.data.cartype == '小型新能源车牌号' || this.data.cartype == '大型新能源车牌号') {
      this.setData({
        carnumber: this.data.inputPlates.index0 + this.data.inputPlates.index1 + this.data.inputPlates.index2 + this.data.inputPlates.index3 + this.data.inputPlates.index4 + this.data.inputPlates.index5 + this.data.inputPlates.index6 + this.data.inputPlates.index7
      });
    } else {
      this.setData({
        carnumber: this.data.inputPlates.index0 + this.data.inputPlates.index1 + this.data.inputPlates.index2 + this.data.inputPlates.index3 + this.data.inputPlates.index4 + this.data.inputPlates.index5 + this.data.inputPlates.index6
      });
    }
    var a = this,
      e = t.target.dataset.index;
    if (0 == e) {
      switch (parseInt(this.data.inputOnFocusIndex)) {
        case 0:
          this.setData({
            "inputPlates.index0": "",
            inputOnFocusIndex: "0"
          });
          break;

        case 1:
          this.setData({
            "inputPlates.index1": "",
            inputOnFocusIndex: "0"
          });
          break;

        case 2:
          this.setData({
            "inputPlates.index2": "",
            inputOnFocusIndex: "1"
          });
          break;

        case 3:
          this.setData({
            "inputPlates.index3": "",
            inputOnFocusIndex: "2"
          });
          break;

        case 4:
          this.setData({
            "inputPlates.index4": "",
            inputOnFocusIndex: "3"
          });
          break;

        case 5:
          this.setData({
            "inputPlates.index5": "",
            inputOnFocusIndex: "4"
          });
          break;

        case 6:
          this.setData({
            "inputPlates.index6": "",
            inputOnFocusIndex: "5"
          });
          break;

        case 7:
          this.setData({
            "inputPlates.index7": "",
            inputOnFocusIndex: "6"
          });
      }
      this.checkedSubmitButtonEnabled();
    } else 1 == e && a.setData({
      isKeyboard: !1,
      isNumberKB: !1,
      inputOnFocusIndex: ""
    });
  },
  //键盘切换
  checkedKeyboard: function () {
    var t = this;
    "0" == this.data.inputOnFocusIndex ? t.setData({
      tapNum: !1,
      isNumberKB: !1
    }) : "1" == this.data.inputOnFocusIndex ? t.setData({
      tapNum: !1,
      isNumberKB: !0
    }) : this.data.inputOnFocusIndex.length > 0 && t.setData({
      tapNum: !0,
      isNumberKB: !0
    });
  },

  checkedSubmitButtonEnabled: function () {
    this.checkedKeyboard();
    var t = !0;
    for (var a in this.data.inputPlates)
      if ("index7" != a && this.data.inputPlates[a].length < 1) {
        t = !1;
        break;
      }
  },
  onUnload () {
    // 页面卸载时设置插件选点数据为null，防止再次进入页面，geLocation返回的是上次选点结果
    chooseLocation.setLocation(null);
  },
})


